package com.ctshk.sapp.season.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.season.dto.FixedSeasonDetailsDTO;
import com.ctshk.rpc.season.dto.FixedSeasonProductPageDTO;
import com.ctshk.rpc.season.dto.SeasonProductStrategyInfoDTO;
import com.ctshk.rpc.season.req.SearchFixedProductReq;
import com.ctshk.rpc.season.req.SeasonProductStrategyInfoReq;
import com.ctshk.rpc.season.req.SeasonProductStrategyQueryByDateReq;
import com.ctshk.rpc.season.service.ISeasonProductStrategyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.xml.transform.Source;

/**
 * <p>
 * 套票产品成本策略表 前端控制器
 * </p>
 *
 * @author 杨林
 * @since 2021-03-15
 */
@Api(value = "产品套票-固定套票产品成本策略", tags = "产品套票-固定套票产品成本策略")
@RestController
@RequestMapping("/season-product-strategy")
public class SeasonProductStrategyController extends BaseController {


    @DubboReference
    private ISeasonProductStrategyService seasonProductStrategyService;


    @ApiOperation(value = "产品中心-固定套票-产品分页查询列表", notes = "产品中心-固定套票-产品分页查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "产品中心固定套票分页查询列表", operDesc = "产品中心固定套票分页查询列表")
    @PostMapping("/list")
    public Result<PageResponse<FixedSeasonProductPageDTO>> list(@RequestBody SearchFixedProductReq req) {
        TokenUser user = getCurrentUser(getRequest());
        PageResponse<FixedSeasonProductPageDTO> response = seasonProductStrategyService.searchProductCenterSeasonFixed(req, user);
        return Result.success(response);

    }


    @ApiOperation(value = "产品中心-固定套票加幅设置-新增或修改", notes = "产品中心-固定套票加幅设置-新增或修改")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.ADD, operTitle = "产品中心固定套票产品加幅策略-新增或修改", operDesc = "产品中心固定套票产品加幅策略-新增或修改")
    @PostMapping("/save")
    public Result saveSeasonProductStrategy(@RequestBody @Valid SeasonProductStrategyInfoReq infoReq) {
        TokenUser user = getCurrentUser(getRequest());
        return seasonProductStrategyService.saveSeasonProductStrategy(infoReq, user);
    }


    @ApiOperation(value = "产品中心-固定套票加幅设置-根据固定套票产品id获取加幅详情信息 ", notes = "产品中心-固定套票加幅设置-根据固定套票产品id获取加幅详情信息")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "根据固定套票产品id获取该产品加幅详情信息", operDesc = "根据固定套票产品id获取该产品加幅详情信息")
    @PostMapping("/queryByProductId")
    public Result<SeasonProductStrategyInfoDTO> querySeasonProductStrategy(@RequestParam(value = "productId", required = true) Long productId) {
        return seasonProductStrategyService.queryByProductId(productId);
    }


    @ApiOperation(value = "产品中心-固定套票-根据日期查询加幅详情信息 ", notes = "产品中心-固定套票加幅设置-根据日期查询加幅详情信息")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "根据日期查询加幅详情信息", operDesc = "根据日期查询加幅详情信息")
    @PostMapping("/queryByDate")
    public Result<FixedSeasonDetailsDTO> queryBydate(@RequestBody @Valid SeasonProductStrategyQueryByDateReq queryByDateReq) {

        return seasonProductStrategyService.queryBydate(queryByDateReq);

    }

    @ApiOperation(value = "产品中心-固定套票-推荐设置 ", notes = "产品中心-固定套票加幅设置-推荐设置")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.UPDATE, operTitle = "固定套票推荐", operDesc = "固定套票推荐")
    @PostMapping("/setRecommend")
    public Result setRecommend(@RequestBody SearchFixedProductReq req) {
        return seasonProductStrategyService.setRecommend(req.getSeasonTypeId(), req.getIsRecommend());
    }


}
